{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "682e768d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import glob\n",
    "import os\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import json\n",
    "import seaborn as sns\n",
    "import pickle as pkl\n",
    "import copy\n",
    "import matplotlib.patches as mpatches\n",
    "from utils import OPT_PATH as opt_path\n",
    "# refer to https://matplotlib.org/stable/api/markers_api.html\n",
    "markers = [\"o\", \"v\", \"s\", \"*\", \"D\"]\n",
    "# refer to https://matplotlib.org/stable/gallery/color/named_colors.html\n",
    "colors = ['tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray']\n",
    "# https://matplotlib.org/3.1.0/gallery/lines_bars_and_markers/linestyles.html\n",
    "linestyles = 'solid'\n",
    "# refer to https://github.com/bvalgard/Boxplots/blob/master/Boxplots.ipynb"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e4de0ef",
   "metadata": {},
   "source": [
    "## Universality v.s. Transferability"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4e0b03a5",
   "metadata": {},
   "source": [
    "### I-FGSM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "75172213",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = glob.glob(os.path.join(opt_path, '*-DTMI-*motivation_IFGSM/eval_universal.npy'))\n",
    "json_path = glob.glob(os.path.join(opt_path, '*-DTMI-*motivation_IFGSM/pert_to_OriImageInd.json'))\n",
    "eval_universal = np.load(path[0])\n",
    "with open(json_path[0], 'r') as ipt:\n",
    "    pert_to_OriImageInd = json.load(ipt)\n",
    "# obtain each pert's white-box universal \n",
    "ifgsm_white_universal = []\n",
    "for pert_ind in range(1000):\n",
    "    preds = eval_universal[2][pert_ind]\n",
    "    image_id = pert_to_OriImageInd[str(pert_ind)]\n",
    "    preds = np.delete(preds, image_id)\n",
    "    ifgsm_white_universal.append(np.sum(preds))\n",
    "ifgsm_white_universal = np.array(ifgsm_white_universal)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3250e54",
   "metadata": {},
   "source": [
    "### DTMI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "c9c162e5",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = glob.glob(os.path.join(opt_path, '*-DTMI-*motivation/eval_universal.npy'))\n",
    "json_path = glob.glob(os.path.join(opt_path, '*-DTMI-*motivation/pert_to_OriImageInd.json'))\n",
    "eval_universal = np.load(path[0])\n",
    "with open(json_path[0], 'r') as ipt:\n",
    "    pert_to_OriImageInd = json.load(ipt)\n",
    "# obtain each pert's white-box universal \n",
    "dtmi_white_universal = []\n",
    "for pert_ind in range(1000):\n",
    "    preds = eval_universal[2][pert_ind]\n",
    "    image_id = pert_to_OriImageInd[str(pert_ind)]\n",
    "    preds = np.delete(preds, image_id)\n",
    "    dtmi_white_universal.append(np.sum(preds))\n",
    "dtmi_white_universal = np.array(dtmi_white_universal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "9478b2ae",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADXCAYAAADBR05ZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAj9klEQVR4nO2deZhU1Zn/P18bBAy4sIgoIqBoAv5iS9CowaSjjlsmcYkBMeMWHeMYNDEx7ibgDPNkcflFzcSgJmqi4h6VOCIxQaNREbBFUQioqO2gIANCVJTlnT/OqeZ201V1u7pvV3Xxfp7nPnXvuefe8723q94+6/vKzHAcx8mCLcotwHGc6sUNjOM4meEGxnGczHAD4zhOZriBcRwnM9zAOI6TGW5gHMfJDDcwjuNkRlEDI+m7krZW4CZJcyQd2hHiHMfp3KSpwXzLz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35T8VnyTEF+KGCp76coc/9bU4lfDdeJNT+ri/yzN9TcDo+l7CC+r+L5M8MX03tVC0KzrNGmVklB5uvarwG4zhOZngNxnGczPAajOM4meEGxnGczHAD4zhOZriBcRwnM9zAOI6TGW5gHMfJjP8DM7UxoS7A3KIAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(4,3)) \n",
    "ax1 = fig.add_subplot(111)\n",
    "ind = np.argsort(-ifgsm_white_universal)\n",
    "ax1.bar(range(len(ind)), np.array(ifgsm_white_universal)[ind], width=1, alpha=1, color=sns.color_palette(\"Paired\")[5])\n",
    "# ax1.set_yticks([0.00, 0.10, 0.20, 0.30, 0.40, 0.50])\n",
    "# ax2 = fig.add_subplot(312)\n",
    "ax1.bar(range(len(ind)), np.array(dtmi_white_universal)[ind], width=1, alpha=0.4, color=sns.color_palette(\"Paired\")[1])\n",
    "# ax3 = fig.add_subplot(313)\n",
    "# ax3.bar(range(len(ind)), np.array(local_dtmi_white_universal)[ind], width=1, alpha=0.5, color='orange')\n",
    "\n",
    "\n",
    "labels = ['I-FGSM', 'DTMI'] \n",
    "color = [sns.color_palette(\"Paired\")[5], sns.color_palette(\"Paired\")[1]]\n",
    "patches = [ mpatches.Patch(color=color[i], label=\"{:s}\".format(labels[i]) ) for i in range(len(color)) ] \n",
    "ax=plt.gca()\n",
    "box = ax.get_position()\n",
    "# ax.set_position([box.x0, box.y0, box.width , box.height* 0.8])\n",
    "ax.legend(handles=patches, fontsize=10) #生成legend\n",
    "plt.xlabel('Generated adversarial perturbations')\n",
    "plt.ylabel('Successful attacks on other images')\n",
    "# plt.show()\n",
    "plt.savefig('./figures/perturbation_universality.pdf', format='pdf', bbox_inches = 'tight')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2f6428d1",
   "metadata": {},
   "source": [
    "### SI "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9bdb1f42",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = glob.glob(os.path.join('/share_io02_ssd/zhipeng/targeted_attack_loss/', 'Loss-resnet50-NIPSDataset-SI_DTMI-Target_CE-baseline/eval_universal.npy'))\n",
    "json_path = glob.glob(os.path.join('/share_io02_ssd/zhipeng/targeted_attack_loss/', 'Loss-resnet50-NIPSDataset-SI_DTMI-Target_CE-baseline/pert_to_OriImageInd.json'))\n",
    "eval_universal = np.load(path[0])\n",
    "with open(json_path[0], 'r') as ipt:\n",
    "    pert_to_OriImageInd = json.load(ipt)\n",
    "# obtain each pert's white-box universal \n",
    "SI_white_universal = []\n",
    "for pert_ind in range(1000):\n",
    "    preds = eval_universal[2][pert_ind]\n",
    "    image_id = pert_to_OriImageInd[str(pert_ind)]\n",
    "    preds = np.delete(preds, image_id)\n",
    "    SI_white_universal.append(np.sum(preds))\n",
    "SI_white_universal = np.array(SI_white_universal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c34f2c01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Successful attacks on other images')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADXCAYAAADBR05ZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAjq0lEQVR4nO3deZwU1b338c/XAQEDKpuIIAKKJuCjoxKjBhOiXrfcxCVeFnPdotcYg0ZzjXsSMJfnldy4PFFzY1Djkqi4b8QrGhP0atwAx4WAARV1vChIQHFBYfg9f5zTMzXDdHdNT9dMT/t7v179mqrTVXV+XdNzpurUWWRmOOdcFjbp7ACcc9XLCxjnXGa8gHHOZcYLG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XfVUU+8xkKg46/QOhB/d9Fts+M96Z2VUth8KyxZlbJk81XNb+Ccc5lxq9gnHOZ8SsY51xmvIBxzmXGCxjnXGa8gHHOZcYLGOdcZryAcc5l5v8DZOoZaKb3mpYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(4,3)) \n",
    "ax1 = fig.add_subplot(111)\n",
    "ind = np.argsort(-ifgsm_white_universal)\n",
    "ax1.bar(range(len(ind)), np.array(ifgsm_white_universal)[ind], width=1, alpha=1, color=sns.color_palette(\"Paired\")[5])\n",
    "# ax1.set_yticks([0.00, 0.10, 0.20, 0.30, 0.40, 0.50])\n",
    "# ax2 = fig.add_subplot(312)\n",
    "ax1.bar(range(len(ind)), np.array(SI_white_universal)[ind], width=1, alpha=0.4, color=sns.color_palette(\"Paired\")[1])\n",
    "# ax3 = fig.add_subplot(313)\n",
    "# ax3.bar(range(len(ind)), np.array(local_dtmi_white_universal)[ind], width=1, alpha=0.5, color='orange')\n",
    "\n",
    "\n",
    "labels = ['I-FGSM', 'DTMI'] \n",
    "color = [sns.color_palette(\"Paired\")[5], sns.color_palette(\"Paired\")[1]]\n",
    "patches = [ mpatches.Patch(color=color[i], label=\"{:s}\".format(labels[i]) ) for i in range(len(color)) ] \n",
    "ax=plt.gca()\n",
    "box = ax.get_position()\n",
    "# ax.set_position([box.x0, box.y0, box.width , box.height* 0.8])\n",
    "ax.legend(handles=patches, fontsize=10) #生成legend\n",
    "plt.xlabel('Generated adversarial perturbations')\n",
    "plt.ylabel('Successful attacks on other images')\n",
    "# plt.show()\n",
    "# plt.savefig('./figures/perturbation_universality.pdf', format='pdf', bbox_inches = 'tight')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e14463ba",
   "metadata": {},
   "source": [
    "### Admix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "9f980f62",
   "metadata": {},
   "outputs": [],
   "source": [
    "path = glob.glob(os.path.join('/share_io02_ssd/zhipeng/targeted_attack_loss/', 'Loss-resnet50-NIPSDataset-Admix_DTMI-Target_CE-baseline/eval_universal.npy'))\n",
    "json_path = glob.glob(os.path.join('/share_io02_ssd/zhipeng/targeted_attack_loss/', 'Loss-resnet50-NIPSDataset-Admix_DTMI-Target_CE-baseline/pert_to_OriImageInd.json'))\n",
    "eval_universal = np.load(path[0])\n",
    "with open(json_path[0], 'r') as ipt:\n",
    "    pert_to_OriImageInd = json.load(ipt)\n",
    "# obtain each pert's white-box universal \n",
    "admix_white_universal = []\n",
    "for pert_ind in range(1000):\n",
    "    preds = eval_universal[2][pert_ind]\n",
    "    image_id = pert_to_OriImageInd[str(pert_ind)]\n",
    "    preds = np.delete(preds, image_id)\n",
    "    admix_white_universal.append(np.sum(preds))\n",
    "admix_white_universal = np.array(admix_white_universal)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "74268414",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Text(0, 0.5, 'Successful attacks on other images')"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADXCAYAAADBR05ZAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAi00lEQVR4nO3deXhV5bn38e/PgICCIoOIDIKKtuqrUdE60DZVj1MHh1oGewStHmudqq2z9gi2vJdtHd46VEWtQyviXBE9orWiR6siYBwQLFQRY1GQglIFBbzfP55nh5WQ7L2S7JXsbO7Pde0raz17Dfde2bmzhmeQmeGcc1nYqK0DcM6VL08wzrnMeIJxzmXGE4xzLjOeYJxzmfEE45zLjCcY51xmPME45zJTMMFI+qmkzRTcKmm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ZJup3wHzKfF4DtJfUm3Cf4VYo4aj+XmU2U9BLhrOoxST8m/PEdROhs6TNJ0xJxrDKztUWKHep2Q5CbThV7A9ZQ975lcv/51kvu+3bgSDN7VdLxhLPflsh973LfOczsckmPEu4fPS/pEDOb28L9NIvf5K3rr0BnST9JlG2SmJ4K/CR2vYCkHWKHR415C+gtad+4fEdJOzey7Oasa/4+JlG+gtDNZs4TwBm5GUmVcfJZ4iB1kg4jXHLVtxnhD+FjSX2Aw2L5XGCQpO3i/KjcChbOsx8CriJcSuS6E2gsjjokbQu8bWbXEFrs7ho/67KYXL5C6JqxkMZiL2RE4ucLTYmd9Y/9AkL3ECj0VZtvUMKNWNeC+lggNyh3N2BR/A79MM++ct4i/G62j/PHEe7pNUrSdmb2upn9mnC/5yv5ls+SJ5iE+Md0JPBNSe9Imk44JT0/LnILofn9LIUOlG8iz1mgmX1B+JL9WtKrhJtujT0RGgvcJ2kmdccGfgQ4SlK1pK8T7hMNVeiQ+U3glLjcOOAbkmYTTpXXGwnezF4l3PSbS7gP8XwsX0W4JHpU0izW9Q2Scw/wn9S9pGssjvqGA2/Ey8ZdCPcQHgc6SJpDGG/rxUbWLRh7CltIeg34KXB2E2N/mnApVS1pBOHSrUc8xqcTWuk35lNg7/g9OQC4LJb/gnAz//n4WXImAecq9NSXS/S5380JhO/G64SzvxsLfOazFDodf43Qgvp/CiyfGW9N7cqWQudZQ82slAebL2t+BuOcy4yfwTjnMuNnMM65zHiCcc5lxhOMcy4znmCcc5nxBOOcy4wnGOdcZv4/hLh5eaPc8dYAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 288x216 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig = plt.figure(figsize=(4,3)) \n",
    "ax1 = fig.add_subplot(111)\n",
    "ind = np.argsort(-ifgsm_white_universal)\n",
    "ax1.bar(range(len(ind)), np.array(ifgsm_white_universal)[ind], width=1, alpha=1, color=sns.color_palette(\"Paired\")[5])\n",
    "# ax1.set_yticks([0.00, 0.10, 0.20, 0.30, 0.40, 0.50])\n",
    "# ax2 = fig.add_subplot(312)\n",
    "ax1.bar(range(len(ind)), np.array(admix_white_universal)[ind], width=1, alpha=0.4, color=sns.color_palette(\"Paired\")[1])\n",
    "# ax3 = fig.add_subplot(313)\n",
    "# ax3.bar(range(len(ind)), np.array(local_dtmi_white_universal)[ind], width=1, alpha=0.5, color='orange')\n",
    "\n",
    "\n",
    "labels = ['I-FGSM', 'DTMI'] \n",
    "color = [sns.color_palette(\"Paired\")[5], sns.color_palette(\"Paired\")[1]]\n",
    "patches = [ mpatches.Patch(color=color[i], label=\"{:s}\".format(labels[i]) ) for i in range(len(color)) ] \n",
    "ax=plt.gca()\n",
    "box = ax.get_position()\n",
    "# ax.set_position([box.x0, box.y0, box.width , box.height* 0.8])\n",
    "ax.legend(handles=patches, fontsize=10) #生成legend\n",
    "plt.xlabel('Generated adversarial perturbations')\n",
    "plt.ylabel('Successful attacks on other images')\n",
    "# plt.show()\n",
    "# plt.savefig('./figures/perturbation_universality.pdf', format='pdf', bbox_inches = 'tight')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "800e0f1e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
